package com.youth.koodoReaderManager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youth.koodoReaderManager.entity.Book;
import com.youth.koodoReaderManager.mapper.BookMapper;
import com.youth.koodoReaderManager.service.BookService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper,Book> implements BookService {

    private final BookMapper bookMapper;

    public BookServiceImpl(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    @Override
    public List<Book> pageQuery(IPage<Book> page, String query) {
        // 创建分页查询条件
        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
        if (query != null && !query.isEmpty()) {
            queryWrapper.like("name", query).or().like("author", query);
        }
        // 执行分页查询
        return bookMapper.selectPage(page, queryWrapper).getRecords();
    }
}